package syn;

public class TestSiSuo {
	public static void main(String[] args) {
		Quhuazhuang g1 = new Quhuazhuang(0, "白雪宫主");
		Quhuazhuang g2 = new Quhuazhuang(1, "灰姑娘");
		new Thread(g1).start();
		new Thread(g2).start();
	}
}

class KouHong {
}

class JingZi {
}

class Quhuazhuang implements Runnable {
	static KouHong kouhong = new KouHong();
	static JingZi jingzi = new JingZi();
	int dongxi;
	String name;

	public Quhuazhuang(int dongxi, String name) {
		this.dongxi = dongxi;
		this.name = name;
	}

	@Override
	public void run() {
		if (dongxi == 0) {
			synchronized (kouhong) {
				System.out.println(this.name + "我拿到了口红");

			}
			synchronized (jingzi) {
				System.out.println(this.name + "我拿到了镜子");
			}
		} else {
			synchronized (jingzi) {
				System.out.println(this.name + "我拿到了镜子");
			}
			synchronized (kouhong) {
				System.out.println(this.name + "我拿到了口红");
			}
		}

	}
}